
  <template>
  <div class="bf-commont-template">
    <!--<h3>待我审批</h3>   -->
    <div class="clearfix bf-top-button">
      <div class="float-r">
        <div class="float-l">
          <el-input placeholder="请输入员工名称搜索内容" prefix-icon="el-icon-search" v-model="searchData" @keyup.enter.native="quickSearch"></el-input>
        </div>
        <div class="float-l padding-l">
          <el-button @click="showSearch" type="primary">高级筛选</el-button>
        </div>
      </div>
    </div>
    <div class="margin-l margin-r">
      <el-tabs v-model="activeName" @tab-click="handleClick">

        <el-tab-pane :label="'入职'+ tabs.countEntry" status="4" name="countEntry">
          <bf-table :data="userData" :setting="entryListSetting" :rowAction="entryRowAction" @editSubmit="editSubmit" @pageChange="pageChange" ref="table"></bf-table>
        </el-tab-pane>
        <el-tab-pane :label="'试用延期'+ tabs.countDelay" status="0" name="countDelay">
          <bf-table :data="userData" :setting="delayListSetting" :rowAction="delayRowAction" @editSubmit="editSubmit" @pageChange="pageChange" ref="table"></bf-table>
        </el-tab-pane>
        <el-tab-pane :label="'转正申请' + tabs.countConrrection" status="1" name="countConrrection">
          <bf-table :data="userData" :setting="conrrectionListSetting" :rowAction="conrrectionRowAction" @editSubmit="editSubmit" @pageChange="pageChange" ref="table"></bf-table>
        </el-tab-pane>
        <el-tab-pane :label="'调动申请' + tabs.countTurnover" status="2" name="countTurnover">
          <bf-table :data="userData" :setting="turnoverListSetting" :rowAction="turnoverRowAction" @editSubmit="editSubmit" @pageChange="pageChange" ref="table"></bf-table>
        </el-tab-pane>
        <el-tab-pane :label="'离职申请' + tabs.countLeave" status="3" name="countLeave">
          <bf-table :data="userData" :setting="leaveListSetting" :rowAction="leaveRowAction" @editSubmit="editSubmit" @pageChange="pageChange" ref="table"></bf-table>
        </el-tab-pane>
        <el-tab-pane :label="'年度调薪' + tabs.countYear" status="5" name="countYear">
          <bf-table :data="userData" :setting="yearListSetting" :rowAction="yearRowAction" @editSubmit="editSubmit" @pageChange="pageChange" ref="table"></bf-table>
        </el-tab-pane>
      </el-tabs>
    </div>

    <!--高级搜索 -->
    <bf-table-search :editForm='searchSetting' :title="'高级搜索'" ref='searchRosterRef' @formSubmit='searchRosterSubmit'></bf-table-search>
    <!-- 入职审批 -->
    <bf-table-edit :width="800" :rowNum="2" :editForm='entryApproveSetting' :title="'入职审批'" :submitButtons="entryApproveSubmitButtons" ref='entryApproveRef' :editRules="addRules"></bf-table-edit>
    <!--入职详情-->
    <bf-table-detail :width="800" :rowNum="2" ref="entryDetailRef" :title="'入职详情'" :editForm="entryDetailSetting" :showHistory='true' :approveSetting='entrySettingHis'></bf-table-detail>

    <!-- 延期审批 -->
    <bf-table-edit :editForm='delayApproveSetting' :title="'延期审批'" :submitButtons="delayApproveSubmitButtons" ref='delayApproveRef' :editRules="addRules"></bf-table-edit>
    <!--延期详情-->
    <bf-table-detail ref="delayDetailRef" :title="'延期详情'" :editForm="delayDetailSetting"
    :showHistory='true' :approveSetting='delaySettingHis'
    ></bf-table-detail >
    <!-- 转正详情 -->
    <bf-table-detail :width="800" :rowNum="2" ref="conrrectionDetailRef" :title="'转正详情'" :editForm="conrrectionDetailSetting" :showHistory='true' :approveSetting='conrrectionSettingHis'></bf-table-detail>
    <!-- 转正审批 -->
    <bf-table-edit :width="800" :rowNum="2" :editForm='conrrectionApproveSetting' :title="'转正审批'" :submitButtons="conrrectionApproveSubmitButtons" ref='conrrectionApproveRef' :editRules="addRules"></bf-table-edit>
    <!--调离详情-->
    <bf-table-detail :width="800" :rowNum="2" ref="turnoverDetailRef" :title="'调动详情'" :editForm="turnoverDetailSetting" :showHistory='true' :approveSetting='turnoverSettingHis'></bf-table-detail>
    <!-- 调动审批 -->
    <bf-table-edit :width="800" :rowNum="2" :editForm='turnoverApproveSetting' :title="'调动审批'" :submitButtons="turnoverApproveSubmitButtons" ref='turnoverApproveRef' :editRules="addRules"></bf-table-edit>

    <!--离职详情-->
    <bf-table-detail :width="800" :rowNum="2" ref="leaveDetailRef" :title="'离职详情'" :editForm="leaveDetailSetting" :showHistory='true' :approveSetting='leaveSettingHis'></bf-table-detail>
    <!-- 离职审批 -->
    <bf-table-edit :width="800" :rowNum="2" :editForm='leaveApproveSetting' :title="'离职审批'" :submitButtons="leaveApproveSubmitButtons" ref='leaveApproveRef' :editRules="addRules"></bf-table-edit>

    <!--年度详情-->
    <bf-table-detail :width="800" :rowNum="2" ref="yearDetailRef" :title="'年度调薪详情'" :editForm="yearDetailSetting" :showHistory='true' :approveSetting='yearSettingHis'></bf-table-detail>
    <!-- 年度审批 -->
    <bf-table-edit :width="800" :rowNum="2" :editForm='yearApproveSetting' :title="'年度调薪审批'" :submitButtons="yearApproveSubmitButtons" ref='yearApproveRef' :editRules="addRules"></bf-table-edit>

  </div>
</template>

<script>
import { findStatusCount, getEntryList, getYearIngList, getDealDelayList, getConrrectionList, getTurnoverList, getLeaveList, findEntryDetail, findYearDetail, findDelayDetail, findConrrectDetail, findTurnoverDetail, findLeaveDetail, dealEntryApprove, dealDelayApprove, dealConrrectionApprove, dealTurnoverApprove, dealLeaveApprove, dealYearApprove } from './api.js'
import { searchSetting, entryListSetting, entryDetailSetting, entryApproveSetting, delayListSetting, delayDetailSetting, delayApproveSetting, conrrectionListSetting, conrrectionDetailSetting, conrrectionApproveSetting, turnoverListSetting, turnoverDetailSetting, turnoverApproveSetting, leaveListSetting, leaveDetailSetting, leaveApproveSetting, yearListSetting, yearDetailSetting, yearApproveSetting } from './table.setting.js'
export default {
  data() {
    return {
      entrySettingHis: {
        procDefKey: 'employee-entry',
        businessKey: ''
      },
      delaySettingHis: {
        procDefKey: 'employee-delay',
        businessKey: ''
      },
      conrrectionSettingHis: {
        procDefKey: 'employee-conrrection',
        businessKey: ''
      },
      turnoverSettingHis: {
        procDefKey: 'employee-turnover',
        businessKey: ''
      },
      leaveSettingHis: {
        procDefKey: 'employee-leave',
        businessKey: ''
      },
      yearSettingHis: {
        procDefKey: 'employee-year',
        businessKey: ''
      },
      searchData: '',
      activeName: 'countEntry',
      statusData: {},

      entryApproveSubmitButtons: [ // 入职
        {
          title: '同意',
          click: (form) => {
            form.action = 1
            this.EntryApprove(form)
          }
        },
        {
          title: '不同意',
          click: (form) => {
            form.action = '0'
            this.EntryApprove(form)
          }
        },
        {
          title: '取消',
          validate: false,
          click: (form) => {
            this.$refs.entryApproveRef.hiden()
          }
        }
      ],
      delayApproveSubmitButtons: [
        {
          title: '同意',
          click: (form) => {
            form.action = 1
            this.delayApprove(form)
          }
        },
        {
          title: '不同意',
          click: (form) => {
            form.action = '0'
            // console.log(form)

            this.delayApprove(form)
          }
        },
        {
          title: '取消',
          validate: false,
          click: (form) => {
            this.$refs.delayApproveRef.hiden()
          }
        }
      ],

      conrrectionApproveSubmitButtons: [
        {
          title: '同意',
          click: (form) => {
            form.action = 1
            this.conrrectionApprove(form)
          }
        },
        {
          title: '不同意',
          click: (form) => {
            form.action = '0'
            // console.log(form)

            this.conrrectionApprove(form)
          }
        },
        {
          title: '取消',
          validate: false,
          click: (form) => {
            this.$refs.conrrectionApproveRef.hiden()
          }
        }
      ],
      turnoverApproveSubmitButtons: [
        {
          title: '同意',
          click: (form) => {
            form.action = 1
            this.turnoverApprove(form)
          }
        },
        {
          title: '不同意',
          click: (form) => {
            form.action = '0'
            // console.log(form)

            this.turnoverApprove(form)
          }
        },
        {
          title: '取消',
          validate: false,
          click: (form) => {
            this.$refs.turnoverApproveRef.hiden()
          }
        }
      ],
      leaveApproveSubmitButtons: [
        {
          title: '同意',
          click: (form) => {
            form.action = 1
            this.leaveApprove(form)
          }
        },
        {
          title: '不同意',
          click: (form) => {
            form.action = '0'
            // console.log(form)

            this.leaveApprove(form)
          }
        },
        {
          title: '取消',
          validate: false,
          click: (form) => {
            this.$refs.leaveApproveRef.hiden()
          }
        }

      ],
      yearApproveSubmitButtons: [ // 年度
        {
          title: '同意',
          click: (form) => {
            form.action = 1
            this.yearApprove(form)
          }
        },
        {
          title: '不同意',
          click: (form) => {
            form.action = '0'
            // console.log(form)

            this.yearApprove(form)
          }
        },
        {
          title: '取消',
          validate: false,
          click: (form) => {
            this.$refs.yearApproveRef.hiden()
          }
        }

      ],
      tabs: {
        countEntry: 0,
        countDelay: 0,
        countConrrection: 0,
        countTurnover: 0,
        countLeave: 0,
        countYear: 0,
      },
      userData: {
      },
      entryRowAction: [
        {
          label: '详情',
          click: (item) => {
            this.entrySettingHis.businessKey = item.scope.row.id
            this.findDetailById(item.scope.row.id, this.$refs.entryDetailRef.show)
          }
        },
        {
          label: '审批',
          hiddenStatus: (row) => {
            if (row.taskDefKey === 'approve') {
              return true
            } else {
              return false
            }
          },
          click: (item) => {
            if (item.scope.row.taskDefKey === 'approve') {
              this.findDetailById(item.scope.row.id, this.$refs.entryApproveRef.show)
            } else {
              this.$message({
                message: '该阶段不可审批',
                type: 'error'
              })
              return false
            }
          }
        }

      ],
      delayRowAction: [
        {
          label: '详情',
          click: (item) => {
            this.delaySettingHis.businessKey = item.scope.row.id
            this.findDetailById(item.scope.row.id, this.$refs.delayDetailRef.show)
          }
        },
        {
          label: '审批',
          hiddenStatus: (row) => {
            if (row.taskDefKey === 'approve') {
              return true
            } else {
              return false
            }
          },
          click: (item) => {
            if (item.scope.row.taskDefKey === 'approve') {
              this.findDetailById(item.scope.row.id, this.$refs.delayApproveRef.show)
            } else {
              this.$message({
                message: '该阶段不可审批',
                type: 'error'
              })
              return false
            }
          }
        }

      ],
      conrrectionRowAction: [
        {
          label: '详情',
          click: (item) => {
            this.conrrectionSettingHis.businessKey = item.scope.row.id
            this.findDetailById(item.scope.row.id, this.$refs.conrrectionDetailRef.show)
          }
        },
        {
          label: '审批',
          hiddenStatus: (row) => {
            if (row.taskDefKey === 'approve') {
              return true
            } else {
              return false
            }
          },
          click: (item) => {
            if (item.scope.row.taskDefKey === 'approve') {
              this.findDetailById(item.scope.row.id, this.$refs.conrrectionApproveRef.show)
            } else {
              this.$message({
                message: '该阶段不可审批',
                type: 'error'
              })
              return false
            }
          }
        }

      ],
      turnoverRowAction: [
        {
          label: '详情',
          click: (item) => {
            this.turnoverSettingHis.businessKey = item.scope.row.id
            this.findDetailById(item.scope.row.id, this.$refs.turnoverDetailRef.show)
          }
        },
        {
          label: '审批',
          hiddenStatus: (row) => {
            if (row.taskDefKey === 'approve') {
              return true
            } else {
              return false
            }
          },
          click: (item) => {
            if (item.scope.row.taskDefKey === 'approve') {
              this.findDetailById(item.scope.row.id, this.$refs.turnoverApproveRef.show)
            } else {
              this.$message({
                message: '该阶段不可审批',
                type: 'error'
              })
              return false
            }
          }
        }

      ],
      leaveRowAction: [
        {
          label: '详情',
          click: (item) => {
            this.leaveSettingHis.businessKey = item.scope.row.id
            this.findDetailById(item.scope.row.id, this.$refs.leaveDetailRef.show)
          }
        },
        {
          label: '审批',
          hiddenStatus: (row) => {
            if (row.taskDefKey === 'approve') {
              return true
            } else {
              return false
            }
          },
          click: (item) => {
            if (item.scope.row.taskDefKey === 'approve') {
              this.findDetailById(item.scope.row.id, this.$refs.leaveApproveRef.show)
            } else {
              this.$message({
                message: '该阶段不可审批',
                type: 'error'
              })
              return false
            }
          }
        }

      ],
      yearRowAction: [
        {
          label: '详情',
          click: (item) => {
            this.yearSettingHis.businessKey = item.scope.row.id
            this.findDetailById(item.scope.row.id, this.$refs.yearDetailRef.show)
          }
        },
        {
          label: '审批',
          hiddenStatus: (row) => {
            if (row.taskDefKey === 'approve') {
              return true
            } else {
              return false
            }
          },
          click: (item) => {
            if (item.scope.row.taskDefKey === 'approve') {
              this.findDetailById(item.scope.row.id, this.$refs.yearApproveRef.show)
            } else {
              this.$message({
                message: '该阶段不可审批',
                type: 'error'
              })
              return false
            }
          }
        }

      ],
      searchSetting: searchSetting, // 高级搜索
      entryListSetting: entryListSetting, // 入职
      entryDetailSetting: entryDetailSetting,
      entryApproveSetting: entryApproveSetting,
      delayListSetting: delayListSetting, // 延期列表
      delayDetailSetting: delayDetailSetting,
      delayApproveSetting: delayApproveSetting,
      conrrectionListSetting: conrrectionListSetting, // 转正
      conrrectionDetailSetting: conrrectionDetailSetting,
      conrrectionApproveSetting: conrrectionApproveSetting,

      turnoverListSetting: turnoverListSetting, // 调离
      turnoverDetailSetting: turnoverDetailSetting,
      turnoverApproveSetting: turnoverApproveSetting,
      leaveListSetting: leaveListSetting, // 离职
      leaveDetailSetting: leaveDetailSetting,
      leaveApproveSetting: leaveApproveSetting,


      yearListSetting: yearListSetting, // 年度
      yearDetailSetting: yearDetailSetting,
      yearApproveSetting: yearApproveSetting,

      addRules: {
        reqName: [
          { required: true, message: '请输入需求名称', trigger: 'blur' },
          { min: 3, max: 50, message: '长度在 3 到 50个字符', trigger: 'blur' }
        ],
        approvalOpinion: [
          { required: true, message: '审批意见必填', trigger: 'blur' }
        ]
      },
      stopRules: {
        stopReason: [
          { required: true, message: '请输入停止招聘原因', trigger: 'blur' },
          { min: 3, max: 50, message: '长度在 3 到 50个字符', trigger: 'blur' }
        ]
      },
      searchParams: {
        page: 1
      }
    }
  },
  mounted: function() {
    this.searchList()
  },
  methods: {

    searchRosterSubmit(form) { // 高级搜索
      this.searchParams.page = 1
      this.searchParams.employeeName = form.employeeName
      this.searchParams.employeeNo = form.employeeNo
      this.searchParams.entryDate = form.entryDate
      this.searchParams.status = form.status
      this.searchParams.orgId = form.orgId
      this.searchParams.post = form.post
      this.searchParams.postLevel = form.postLevel

      this.searchList()
      this.$refs.searchRosterRef.hiden()
    },

    EntryApprove(form) {
      // 入职同意不同意
      dealEntryApprove(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.entryApproveRef.hiden()
          this.searchList()
        }
      })
    },


    delayApprove(form) { // 延期同意不同意
      dealDelayApprove(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.delayApproveRef.hiden()
          this.searchList()
        }
      })
    },
    conrrectionApprove(form) { // 转正
      dealConrrectionApprove(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.conrrectionApproveRef.hiden()
          this.searchList()
        }
      })
    },
    turnoverApprove(form) { // 调离
      dealTurnoverApprove(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.turnoverApproveRef.hiden()
          this.searchList()
        }
      })
    },

    leaveApprove(form) { // 离职
      dealLeaveApprove(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.leaveApproveRef.hiden()
          this.searchList()
        }
      })
    },

    yearApprove(form) { // 年度
      // console.log(form)
      dealYearApprove(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.yearApproveRef.hiden()
          this.searchList()
        }
      })
    },

    // dealDelayApprove,dealConrrectionApprove,dealTurnoverApprove,dealLeaveApprove

    getTabs(status) {
      // this.tabs.countConrrection = 0
      // this.tabs.countTurnover = 0
      // this.tabs.countLeave = 0
      // this.tabs.countDelay = 0
      findStatusCount(status).then((request) => {
        this.tabs.countEntry = request.data[0].countEntry
        this.tabs.countDelay = request.data[0].countDelay
        this.tabs.countConrrection = request.data[0].countConrrection
        this.tabs.countTurnover = request.data[0].countTurnover
        this.tabs.countLeave = request.data[0].countLeave
        this.tabs.countYear = request.data[0].countYear

        // this.statusData.forEach((v) => {
        //   if(v.status === '0'){
        //     this.tabs.countDelay = v.count
        //   }
        //   if(v.status === '1'){
        //     this.tabs.countTurnover = v.count
        //   }
        //   if(v.status === '2'){
        //     this.tabs.recruitCount = v.count
        //   }
        //   if(v.status === '3'){
        //     this.tabs.countLeave = v.count
        //   }

        //   if(v.status === '4'){
        //     this.tabs.countEntry = v.count
        //   }
        //   if(v.status === '5'){
        //     this.tabs.countYear = v.count
        //   }
        // })
      })
    },


    findDetailById(Id, showCall) { // 详情
      const status = this.getActivityStatus()
      const params = {
        id: Id
      }
      if (status === 0) {
        findDelayDetail(params).then((response) => {
          showCall(response.data)
        })
      }
      if (status === 1) {
        findConrrectDetail(params).then((response) => {
          showCall(response.data)
        })
      }
      if (status === 2) {
        findTurnoverDetail(params).then((response) => {
          showCall(response.data)
        })
      }
      if (status === 3) {
        findLeaveDetail(params).then((response) => {
          showCall(response.data)
        })
      }
      if (status === 4) { // 入职
        findEntryDetail(params).then((response) => {
          showCall(response.data)
        })
      }
      if (status === 5) { // 年假
        findYearDetail(params).then((response) => {
          showCall(response.data)
        })
      }
    },


    searchList() {
      if (!this.searchParams.status) {
        this.searchParams.status = '1'
      }
      this.getTabs(this.searchParams.status)
      const pageParams = this.searchParams
      const status = this.getActivityStatus()
      if (status === 0) {
        getDealDelayList(pageParams).then((response) => {
          this.userData = response
        })
      }
      if (status === 1) {
        getConrrectionList(pageParams).then((response) => {
          this.userData = response
        })
      }
      if (status === 2) {
        getTurnoverList(pageParams).then((response) => {
          this.userData = response
        })
      }
      if (status === 3) {
        getLeaveList(pageParams).then((response) => {
          this.userData = response
        })
      }
      if (status === 4) { // 入职 getEntryList,getYearIngList
        getEntryList(pageParams).then((response) => {
          this.userData = response
        })
      }
      if (status === 5) { // 年度  findEntryIng, findYearIng
        getYearIngList(pageParams).then((response) => {
          this.userData = response
        })
      }
    },

    editSubmit(params, formType, formList) {
    },
    pageChange(pageObj) {
      this.searchParams.page = pageObj.page
      this.searchParams.pageSize = pageObj.pageSize
      this.searchList()
    },
    showSearch() {
      this.$refs.searchRosterRef.show()
    },
    addreq() {
      this.$refs.addRosterRef.show()
    },
    quickSearch() {
      // const params = {
      //   id: this.searchData
      // }
      // console.log(params)
      this.searchParams.page = 1
      this.searchParams.employeeName = this.searchData
      this.searchList()
    },
    handleClick(tab, event) {
      this.searchParams.page = 1
      this.searchList()
    },

    getActivityStatus() {
      if (this.activeName === 'countDelay') {
        return 0;
      }
      if (this.activeName === 'countConrrection') {
        return 1;
      }
      if (this.activeName === 'countTurnover') {
        return 2;
      }
      if (this.activeName === 'countLeave') {
        return 3;
      }
      if (this.activeName === 'countEntry') {
        return 4;
      }
      if (this.activeName === 'countYear') {
        return 5;
      }
    }
  }
}
</script>

<style scoped>

</style>
